package gui;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JPanel;
import javax.swing.JPopupMenu;

public class MousePopupListener extends MouseAdapter {

	private JPanel parent;
	private JPopupMenu popup;

	private void checkPopup(MouseEvent e) {
		if (e.getButton() > 1) {
			popup.show(parent, e.getX(), e.getY());
		}
	}

	public JPanel getParent() {
		return parent;
	}

	public JPopupMenu getPopup() {
		return popup;
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		checkPopup(e);
	}

	@Override
	public void mousePressed(MouseEvent e) {
		checkPopup(e);
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		checkPopup(e);
	}

	public void setParent(JPanel parent) {
		this.parent = parent;
	}

	public void setPopup(JPopupMenu popup) {
		this.popup = popup;
	}
}